package sfmc.biz.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import sfmc.biz.service.SfmcOptionService;
import sfmc.biz.vo.Sfmc_TB_OPTION;

@Controller
public class SfmcOptionController {
	
	protected Log log = LogFactory.getLog(this.getClass());
	
	@Autowired 
	private SfmcOptionService sfmcOptionService;
	
	@RequestMapping(value ="/option_list.do")
	public ModelAndView list(ModelAndView mav, HttpSession session, HttpServletRequest request, Sfmc_TB_OPTION sfmc_TB_OPTION){
		
		ModelAndView mv = new ModelAndView("/option/option_list");
	
		List<Sfmc_TB_OPTION> optionList = sfmcOptionService.getOptionList(sfmc_TB_OPTION);
		
		mv.addObject("optionlist", optionList);
		return mv;
	}
	
	@RequestMapping(value ="/option_save.do" , method = RequestMethod.POST)
	public ModelAndView save(ModelAndView mv, HttpSession session, HttpServletRequest request, Sfmc_TB_OPTION sfmc_TB_OPTION){
		
		mv.setViewName("/option/option_result");

		int returnVal = -1;
		String type = "U";

		sfmc_TB_OPTION.setStartLongWeekend(sfmc_TB_OPTION.getStartLongWeekend().replaceAll("-", ""));
		sfmc_TB_OPTION.setEndLongWeekend(sfmc_TB_OPTION.getEndLongWeekend().replaceAll("-", ""));
		
		if("".equals(sfmc_TB_OPTION.getCheckHolyday())){
			sfmc_TB_OPTION.setCheckHolyday("0");
		}
		if("".equals(sfmc_TB_OPTION.getCheckWorktime())){
			sfmc_TB_OPTION.setCheckWorktime("0");
		}
		if("".equals(sfmc_TB_OPTION.getCheckLongWeekend())){
			sfmc_TB_OPTION.setCheckLongWeekend("0");
		}
		
		returnVal = sfmcOptionService.updateOption(sfmc_TB_OPTION);
		
		mv.addObject("returnVal", returnVal);
		mv.addObject("type", type);
		return mv;
	}
}
